<template>
  <div class="mesPage">
    <div class="header">
      <div class="tabs">
        <span v-for="(item, index) in tabs" :key="item.type" class="tab-item" :class="{ actived: indexs == index }" @click="actTabs(item, index)">
          {{ item.name }}
        </span>
      </div>
    </div>

    <el-main class="bc main-bg">
      <el-scrollbar class="list-view">
        <div class="cont">
          <el-row>
            <el-col :span="24" class="check">
              <span>只看未读</span>
              <el-checkbox @change="changeCheck" v-model="checked"></el-checkbox>
            </el-col>
          </el-row>
          <template v-if="tableData.length > 0">
            <el-row class="list-item" :class="{ read: item.isRead == 0 }" @click.native="skipItem(item)" v-for="item in tableData" :key="item.id">
              <el-col :span="19">
                <div class="item-tit" :title="item.noticeName">
                  <p>
                    <span class="du-span">{{ item.labelName }}</span>
                    {{ item.noticeName }}
                  </p>
                </div>
              </el-col>
              <el-col class="item-tit tr" :span="5">
                <p>{{ item.createTime }}</p>
              </el-col>
            </el-row>
          </template>
          <Empty v-else></Empty>
        </div>
      </el-scrollbar>
      <div class="pag-box">
        <Pagination :current-page.sync="pageIdx" :page-size.sync="pageSize" :total="totalSize" @currentChange="onCurrentChange" />
      </div>
    </el-main>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Empty from '@com/Empty.vue'
import Pagination from '@com/pagination.vue'
import { listNotice, updateNoticeRead, getNoticeReadCount } from '@api/api.js'
export default {
  name: 'mesPage',
  props: {},
  components: {
    Pagination,
    Empty,
  },
  data() {
    return {
      isRouterAlive: true,
      xnTabs: [
        { type: '', name: '全部' },
        { type: '1', name: '明查暗访' },
        { type: '2', name: '追溯反馈' },
        { type: '3', name: '指标填报' },
        { type: '4', name: '效能投诉' },
      ],
      orgTabs: [
        { type: '', name: '全部' },
        { type: '2', name: '追溯反馈' },
        { type: '3', name: '指标填报' },
        { type: '4', name: '效能投诉' },
        { type: '5', name: '表彰推广' },
      ],
      indexs: 0,
      checked: false,
      pageIdx: 1,
      pageSize: 6,
      totalSize: 1,
      tableData: [],
      tabsType: '',
      type: this.$route.query.type || '',
    }
  },
  computed: {
    ...mapGetters(['noticeMessage', 'isOrgRole']),
    tabs() {
      if (this.isOrgRole) {
        return this.orgTabs
      }
      return this.xnTabs
    },
  },
  created() {},
  mounted() {
    this.getdata()
    // 获取通知消息数量
    this.getNoticeReadCount()
  },
  watch: {},
  methods: {
    actTabs(item, i) {
      this.pageIdx = 1
      this.indexs = i
      this.tabsType = item.type
      this.getList()
    },
    getdata() {
      this.getList()
    },
    getList() {
      listNotice({
        currentPage: this.pageIdx, // 页码
        pageSize: this.pageSize, // 每页的数量
        param: {
          status: this.checked ? '0' : '',
          type: this.tabsType,
        },
      }).then(res => {
        if (res.status !== 200) {
          this.$message.error(res.message)
        } else {
          this.tableData = res.data.content
          this.totalSize = res.data.totalSize
          this.totalPages = res.data.totalPages
          this.currentPage = res.data.pageNum
        }
      })
    },
    changeCheck() {
      this.pageIdx = 1
      this.getList()
    },
    onCurrentChange() {
      this.getList()
    },
    skipItem(item) {
      if (item.isRead === '0') {
        updateNoticeRead({
          id: item.id,
        }).then(res => {
          if (res.status === 200) {
            item.isRead = '1'
            this.$store.commit('setNoticeMessage', this.noticeMessage - 1)
            this.$router.push({
              path: item.url,
            })
          }
        })
      } else {
        this.$router.push({
          path: item.url,
        })
      }
    },
    // 获取通知消息数量
    getNoticeReadCount() {
      getNoticeReadCount().then(res => {
        if (res.status === 200) {
          this.$store.commit('setNoticeMessage', res.data)
        }
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.mesPage {
  height: 100%;
  background: #fff;
  padding-top: 20px;
  overflow-y: hidden;
  font-size: 14px;
}
.tabs {
  width: 100%;
  height: 32px;
  line-height: 32px;
  top: 119px;
  left: 0;
  right: 0;
  margin: 0 auto;
  text-align: center;
  span {
    display: inline-block;
    height: 32px;
    line-height: 32px;
    background: #e6ebf1;
    width: 140px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    color: #666666;
    position: relative;
    z-index: 99;
  }
  .actived {
    width: 140px;
    height: 40px;
    line-height: 40px;
    box-shadow: 0px -9px 10px 0px rgba(51, 75, 124, 0.2);
    border-bottom: none;
    background: #fff;
    // background-image: url("../../assets/images/message/hw.png");
    // background-size: 55px 36px;
    // background-repeat: no-repeat;
    // background-position: 45px 0;
    color: #2c63b0;
    font-size: 16px;
    font-weight: bold;
    z-index: 105;
  }
  .tab-item {
    margin-left: 10px;
    margin-right: 10px;
  }
}
.bc {
  width: 100%;
  height: calc(100% - 36px);
  position: relative;
  overflow: hidden;
  padding: 0;
}
.main-bg {
  background-image: url('../../assets/images/message/bac4.png');
  background-size: 100% 100%;
}
::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}

::v-deep .el-scrollbar__bar.is-vertical {
  width: 0;
}
.list-view {
  width: 100%;
  height: calc(100% - 71px);
  padding: 30px 30px 0;
  .cont {
    width: 100%;
    padding-right: 10px;
    .check {
      text-align: right;
      margin-bottom: 20px;
      span {
        margin-right: 10px;
        font-size: 16px;
        color: #333333;
      }
    }

    .list-item {
      margin-bottom: 20px;
      padding: 10px 30px;
      border: 1px solid rgba(51, 75, 124, 0.1);
      box-shadow: 0px 0px 10px 0px rgba(51, 75, 124, 0.16);
      cursor: pointer;

      .item-tit {
        border-bottom: 1px solid rgba(51, 75, 124, 0.1);
        height: 55px;
        line-height: 55px;
        display: block;
        // overflow: hidden;
        // white-space: nowrap;
        // text-overflow: ellipsis;
        p {
          font-size: 14px;
          color: #000;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }

        span {
          padding: 7px 8px;
          color: #fff;
          font-size: 14px;
          border-radius: 5px;
          font-weight: 400;
          margin-right: 18px;
        }
        .du-span {
          color: #1870cc;
          background-color: rgba($color: #1870cc, $alpha: 0.16);
        }
      }

      .tr {
        text-align: right;

        span {
          background: none;
          color: #000;
        }
      }
      &:hover {
        border-color: #2d7def;
        position: relative;
        box-shadow: 0px 9px 9px 0px rgba(145, 155, 167, 0.41);
      }
    }
    .read {
      position: relative;
      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 0;
        width: 0;
        height: 0;
        border-top: 24px solid #e76a6a;
        border-right: 24px solid transparent;
      }
    }

    .item-con {
      padding: 10px 0;
      p {
        font-size: 12px;
        line-height: 25px;
      }
    }
  }
}
.pag-box {
  padding: 0 30px;
  width: 100%;
}
::v-deep .el-scrollbar__wrap {
  overflow: auto;
}
</style>
